<?php
require_once  str_replace( '//', '/', dirname( __FILE__ ) . '/' ) . '../ImdbScraper.php';

class TestOfScraper extends UnitTestCase {
	private $imdbScraperModel;
	
	public function __construct() {
		$this->imdbScraper = new ImdbScraper();
	}

	function testScraperRetrievesFreshSource() {
		$scrapedData = $this->imdbScraper->scrapeImdbToplist();
		
		$this->assertIsA( $scrapedData, 'array' );
		$this->assertFalse( $scrapedData['error'] );
		$this->assertTrue( $scrapedData['status'] == 200, "Expected http response code \"200\" but got " . $scrapedData['status'] . "." );
		$this->assertNotNull( $scrapedData['content'] );
	}
	
	function testScraperRetrievesDocument() {
		$documentSource = $this->imdbScraper->getDocumentSource();
		
		$this->assertNotNull( $documentSource );
	}
	
	function testScraperExtractsTop10() {
		$top10Data = $this->imdbScraper->getTop10Data( $this->imdbScraper->getDocumentSource() );
		
		$this->assertIsA( $top10Data, 'array' );
		$this->assertTrue( count( $top10Data ) == 10, "Expected 10 posts but got " . count( $top10Data ) . "." );
	}
}
